package algorithm;

import java.util.*;


public class VersionCompare {

    public static void main(String[] args) {
        compare("1.2","1.1");
        String str= "AWA";
        // split在没有匹配时会返回自身
        String[] s = str.split("\\{");
        System.out.println(s[0]);
    }
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 比较版本号
     * @param version1 string字符串
     * @param version2 string字符串
     * @return int整
     */
    public  static int compare (String version1, String version2) {
        // write code here
        if(version1.equals(version2)){
            return 0;
        }
        String[] arr1=null,arr2=null;
        int[] arr1n,arr2n;
        if(!version1.contains(".")){
            arr1n = new int[1];
            arr1n[0] = Integer.valueOf(version1);
        }else{
            arr1=version1.split("\\.");
            arr1n = new int[arr1.length];
            for(int i=0;i<arr1.length;i++){
                System.out.println(arr1[i]);
                arr1n[i] = Integer.valueOf(arr1[i]);
            }
        }
        if(!version2.contains(".")){
            arr2n =new int[1];
            arr2n[0] = Integer.valueOf(version2);
        }else{
            arr2=version2.split("\\.");
            arr2n =new int[arr2.length];
            for(int i=0;i<arr2.length;i++){
                System.out.println(arr2[i]);
                arr2n[i] = Integer.valueOf(arr2[i]);
            }
        }

        // 1.0 --1.0.0  需要补齐
         int min=Math.min(arr1n.length,arr2n.length);
        for(int i=0;i<min;i++){
            if(arr1n[i]>arr2n[i]){
                return 1;
            }
            if(arr1n[i]< arr2n[i]){
                return -1;
            }
        }

        for(int i=0;i<arr1.length;i++){
            System.out.print(arr1[i]);
        }
        for(int i=0;i<arr2.length;i++){

            System.out.print(arr2[i]);
        }

        // 合法版本号，至少一位数
        if(arr1n.length==arr2n.length){
            return 0;
        }
        if(arr1n.length>arr2n.length){
            return 1;
        }
        return -1;
    }
}